/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-07-10
 * Time: 18:25
 */
public class test1 {
    class TreeNode{
        TreeNode left ;
        TreeNode right;

        public TreeNode(int num) {

        }
    }

    public TreeNode sortedArrayToBST(int[] nums) {
        int left = 0;
        int right = nums.length-1;
        return helper(nums,left,right);
    }

    public TreeNode helper(int[] nums,int left,int right){
        if(left>right){
            return null;
        }
        int mid = (right-left)/2 + left;
        TreeNode root = new TreeNode(nums[mid]);
        root.left =  helper(nums,left,mid-1);
        root.right = helper(nums,mid+1,right);
        return root;
    }
}
